clear
for n=1:12
    clear comb Bez Che Che2 ni chei chei2 Poly Poly2;
    ni = 0:n;
    for i=0:n
        comb(i+1)=nchoosek(n,i);
    end
    for i=0:n
        for j=0:n
        Bez(i+1,j+1) = comb(j+1)*((n-i)^(n-j))*(i^j)/(n^n);
        end
    end

    chei = 1:n+1;
    chei = -cos((2*chei-1)/(2*(n+1))*pi);
    for i=0:n
        for j=0:n
        Poly2(i+1,j+1) = chei(i+1).^(n-j);
        end
    end
    
    chei = (1+chei)/2;
    for i=0:n
        for j=0:n
        Che(i+1,j+1) = comb(j+1)*((1-chei(i+1))^(n-j))*(chei(i+1)^j);
        end
    end
    
    for i=0:n
        for j=0:n
        Poly(i+1,j+1) = chei(i+1).^(n-j);
        end
    end

    chei2 = 1:n+1;
    chei2 = cos(chei2/(n+2)*pi);
    chei2 = (1-chei2)/2;
    for i=0:n
        for j=0:n
        Che2(i+1,j+1) = comb(j+1)*((1-chei2(i+1))^(n-j))*(chei2(i+1)^j);
        end
    end

    con(n,1)=cond(Bez);
    con(n,2)=cond(Che);
    con(n,3)=cond(Che2);
    con(n,4)=cond(Poly);
    con(n,5)=cond(Poly2);
    
    Poly=inv(Poly); Poly=Poly';
    Poly2=inv(Poly2); Poly2=Poly2';
    Bez=inv(Bez); Bez=Bez';
    Che=inv(Che); Che=Che';
    Che2=inv(Che2); Che2=Che2';
    
    
    ind = n*(n+1)*(2*n+1)/6;
    
    poly(ind: ind+n*(n+2)) = Poly(:);
    poly2(ind: ind+n*(n+2)) = Poly2(:);
    bez(ind : ind+n*(n+2)) = Bez(:);
    che(ind : ind+n*(n+2)) = Che(:);
    
    ind = n*(n+1)/2;
    chep(ind : ind+n) = chei(:);
end
fid=fopen('InterMethod.txt', 'w');
fprintf(fid, 'Matrix for function interpolation\n');
fprintf(fid, 'function degree is between 1 and 12\n');
fprintf(fid, 'n degree interpolation matrix index is begin at (n*(n+1)*(2*n+1)/6-1) for c language\n');
fprintf(fid, 'it is stored in row order\n \n');
fprintf(fid, 'function is interpolated at equidistant points xi between 0 and 1 \n');
fprintf(fid, ' %32.16ff,', bez);
fprintf(fid, '\n \n');
fprintf(fid, 'function is interpolated at chebyshev points(nodes) xi between 0 and 1 \n');
fprintf(fid, ' %32.16ff,', che);
fprintf(fid, '\n \n');
fprintf(fid, 'Polynomial function is interpolated at chebyshev points(nodes) xi between 0 and 1 \n');
fprintf(fid, ' %32.16f,', poly);
fprintf(fid, '\n \n');
fprintf(fid, 'Polynomial function is interpolated at chebyshev points(nodes) xi between -1 and 1 \n');
fprintf(fid, ' %32.16ff,', poly2);
fprintf(fid, '\n \n');
fprintf(fid, 'chebyshev points(nodes) xi between 0 and 1 \n');
fprintf(fid, 'n degree index is begin at ( n*(n+1)/2-1) for c language\n');
fprintf(fid, ' %32.16ff,', chep);
fclose(fid);